﻿  <?php
  
  function UpdateLogoFile($file,$folderName)
  {
   require_once("db_mysql.php");
   $folderPath = 'PartyInfo/' . $folderName;
	if(!file_exists($folderPath))
	{
	//xp 系统是gbk 编码 不转换的换文件夹名是乱码
	 $gbkfolderPath = iconv('utf-8' , 'gbk' , $folderPath);
	 mkdir($gbkfolderPath);
	}
	if ((($file['logoFile']['type'] == 'image/gif')
		||($file['logoFile']['type'] == 'image/jpeg')
		|| ($file['logoFile']['type'] == 'image/pjpeg'))
		&& ($file['logoFile']['size'] < 20000))
	{
		if($file['logoFile']['error'] > 0)
		{
		echo 'Return Code: ' . $file['logoFile']['error'] . '<br />';
		return ;
		}
		//party image folder name is partyImg
		$subFolderPath = $folderPath . '/' . 'partyImg';
		if(!file_exists($subFolderPath))
		{
		  $gbkSubFolderPath = iconv('utf-8' , 'gbk' , $subFolderPath);
		  mkdir($gbkSubFolderPath);
		}
		$subFilePath = $subFolderPath . '/' . $file['logoFile']['name'];
		$gbkSubFilePath =iconv('utf-8','gbk',$subFilePath);
		move_uploaded_file($file['logoFile']['tmp_name'],$gbkSubFilePath);	
		$link = new SqlClass();
		$link->connect();	
		$sqlCommand ="insert into album(albumName,albumUrl) values('$folderName','$folderPath')";
		$link->exec_sql($sqlCommand);
		$link->close();
        return $subFilePath;		
	}	
	else
	{
	  echo 'Invalid file ,please check the file type and file size which is shorter than 20k';
	}
  }
  ?>